package com.example.l.zcq1;

import android.content.pm.PackageManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class Main4kjActivity extends AppCompatActivity {
    private FragmentTabHost tabHost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4kj);
        //初始化框架对象
        init();
        //设置Tab
        setTab();
    }
    public void init(){
        tabHost=(FragmentTabHost)findViewById(R.id.tabhost);
    }
    public void  setTab(){
        //框架的不同内容通过tab所进行显示
        FragmentManager fragmentManager=getSupportFragmentManager();

        tabHost.setup(this,fragmentManager,R.id.tablocation);
        tabHost.getTabWidget().setDividerDrawable(null);
        //设置tab标签的相关属性（页面，所谓用的类文件，null）
        tabHost.addTab(tabHost.newTabSpec("environment").setIndicator(setTabview("实时环境")),shishihuanjing.class,null);
        tabHost.addTab(tabHost.newTabSpec("shebeikongzhi").setIndicator(setTabview("设备控制")),shebeikongzhi.class,null);
        tabHost.addTab(tabHost.newTabSpec("shujufenxi").setIndicator(setTabview("数据分析")),shujufenxi.class,null);
        tabHost.addTab(tabHost.newTabSpec("canshu").setIndicator(setTabview("参数设置")),ceshi1.class,null);
    }
    //创建null视图界面
    public View setTabview(String title){
        //通过xml来创建不同的tab标签
        View view=LayoutInflater.from(this).inflate(R.layout.tabhost,null);
        //获取模板当中的文本内容
        TextView textView=(TextView)view.findViewById(R.id.tabhost_textview_title);
        //设置标签
        textView.setText(title);
        return view;
    }
}
